package com.smartticket.jeju.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.smartticket.jeju.model.Sight;
import com.smartticket.jeju.model.Ticket;
import com.smartticket.jeju.service.SightService;
import com.smartticket.jeju.service.TicketService;

@Controller
public class TicketInfoController {

	@Autowired
	private SightService sightService;
	
	@Autowired
	private TicketService ticketService;
	
	@RequestMapping("ticketInfo")
	public ModelAndView ticketInfo(@RequestParam int id, @RequestParam int ticket_id){
		ModelAndView modelAndView = new ModelAndView();
		
		Sight sight = sightService.get(id);
		modelAndView.addObject("sight", sight);
		
		
		Ticket ticket = ticketService.get(ticket_id);
		modelAndView.addObject("ticket", ticket);

		int currentPrice = ticketService.calculatePrice(ticket.getPrice(), ticket.getDiscount_rate());
		modelAndView.addObject("currentPrice", currentPrice);
		
		int totalTicket = ticketService.totalTicket(ticket.getGoal_count());		
		modelAndView.addObject("totalTicket", totalTicket);
		return modelAndView;
	}
	//change
}
